#!/usr/bin/perl
#save_recovery.cgi

require './diskman-lib.pl';

&ReadParse();

my ($err_msg, $log_ev, $log_msg, $log_pri);

$err_msg="";
$log_ev="";

my $mkfs_lock;
$mkfs_lock = check_lock();
if ($mkfs_lock) {
	$err_msg = $text{"err_mkfslocked"};
	goto ERROR_OUT;
}

my ($volname, $adddisk);
$volname = $in{'volname'};
$adddisk = $in{'adddisk'};
$adddisk =~ /(\d+)/;
$dn = $1;
if (!$volname || !$adddisk) {
	$err_msg = $text{"err_cgiparam"};
#	goto ERROR_OUT;
}

my (@rdinfo, @dinfo, @free_disks);

@rdinfo = get_mega_raid_info();
@disks = get_all_lsi_diskinfo();
if ($adddisk =~ /(\d+)/) {
    $dnum = $1;
}
$des = $disks[$dnum]->{'es'};
$uid = $disks[$dnum]->{'status'};

$err_msg= $des;
#goto ERROR_OUT;
system("/sbin/MegaCli -PDHSP -Set -PhysDrv[$des] -a0");

if ($?) {
	$log_ev = $text{'log_ev_recvolume_err'};
	$log_msg= &text('log_msg_recvolume_err', $volname);
	nas_syslog($text{'my_log_minor'}, 'naslog_warning', $log_ev, $log_msg);

	$err_msg = $text{"err_configchanged"};
	goto ERROR_OUT;	
}
$log_ev = $text{'log_ev_recvolume_ok'};
$log_msg= &text('log_msg_recvolume_ok', $volname);
nas_syslog($text{'my_log_minor'}, 'naslog_info', $log_ev, $log_msg);


redirect("index.cgi");

ERROR_OUT:
&error_setup($text{'rec_err_title'});
&error($err_msg);
